home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / switcher.lzh / NRPS.C < prev    next >
C/C++ Source or Header  |  1990-04-04  |  2KB  |  105 lines

  1. #include <tos.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <mydefs.h>
  6.  
  7. char buf[1024];
  8. char ppath[128],dpath[128],ppat2[128];
  9. char files[128][14];
  10. long fleng[128],l;
  11.  
  12. static char *pext  = "\\*.PI3";
  13. static char *dfile = "\\NEOPIC_C.PI3";
  14.  
  15. long getline(
  16.     char    *dest,
  17.     char    *buf,
  18.     long    start,
  19.     long    max)
  20.     {
  21.     long p,q;
  22.     
  23.     q = 0L;
  24.     p = start;
  25.     while((p<max)&&(*(buf+p)<0x20))
  26.         ++p;
  27.     while((p<max)&&(*(buf+p)>0x1f))
  28.         {
  29.         *(dest+q)=*(buf+p);
  30.         ++p;
  31.         ++q;
  32.         }
  33.     *(dest+q) = 0;
  34.     return(p);
  35.     }
  36.  
  37. void main(void)
  38.     {
  39.     int fd;
  40.     DTA *d;
  41.     unt u;
  42.     uln    r;
  43.     char *loc;
  44.     static char *backs="\\";
  45.  
  46.     puts("NRPS V3.0 - with Turbo C 2.0");
  47.     puts("NeoDesk Random Picture Selector");
  48.     puts("BY Gregory Mathias Lemperle-Kerr");
  49.  
  50.     if (Fsfirst("NRPS.INF",0)>=0)
  51.         {
  52.         d=Fgetdta();
  53.         l=d->d_length;
  54.         puts("Using NRPS.INF for paths...");
  55.         fd=Fopen("NRPS.INF",1);
  56.         Fread(fd,l,buf);
  57.         Fclose(fd);
  58.         getline(dpath,buf,getline(ppath,buf,0,l),l);
  59.         }
  60.     else
  61.         {
  62.         strcpy(ppath,"E:\\CLIPART");
  63.         strcpy(dpath,"C:\\NEODESK");
  64.         }
  65.     *(pext+5)=(*(dfile+12)='1'+Getrez());
  66.     if (Getrez()==2)
  67.         *(dfile+8)='M';
  68.     strcpy(ppat2,ppath);
  69.     strcat(ppath,pext);
  70.     strcat(dpath,dfile);
  71.     strcat(ppat2,backs);
  72.     puts(ppath);
  73.     puts(dpath);
  74.     u = 0;
  75.     if ((fd=Fsfirst(ppath,0))>=0) while (fd>=0)
  76.         {
  77.         d=Fgetdta();
  78.         strncpy(files[u],d->d_fname,14);
  79.         fleng[u]=d->d_length;
  80.         fd = Fsnext();
  81.         ++u;
  82.         }
  83.     else
  84.         {
  85.         puts("NO PICTURES FOUND!\007");
  86.         return;
  87.         }
  88.     r=(Random()+Gettime())%u;
  89.     puts(files[r]);
  90.     puts("Copying...");
  91.     if(Fsfirst(dpath,0)<0)
  92.         {
  93.         fd=Fcreate(dpath,0);
  94.         Fclose(fd);
  95.         }
  96.     loc = (char *)Physbase()-34;
  97.     strcat(ppat2,files[r]);
  98.     fd=Fopen(ppat2,READ);
  99.     Fread(fd,fleng[r],loc);
  100.     Fclose(fd);
  101.     fd=Fopen(dpath,WRITE);
  102.     Fwrite(fd,fleng[r],loc);
  103.     Fclose(fd);
  104.     }
  105.